#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int num1[26], num2[26];

void solve() {
	int n, k; cin >> n >> k;
	string a, b; cin >> a >> b;
	memset(num1, 0, sizeof num1);
	memset(num2, 0, sizeof num2);
	for (int i = 0; i < n; i++) {
		num1[a[i] - 'a']++;
		num2[b[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (num1[i] != num2[i]) {
			cout << "NO" << endl;
			return;
		}
	}
	for (int i = 0; i < n; i++) {
		if (i - k < 0 && i + k >= n) {
			if (a[i] != b[i]) {
				cout << "NO" << endl;
				return;
			}
		}
	}
	cout << "YES" << endl;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}